package com.tanhua.app.controller;

import com.tanhua.app.Service.CommentService;
import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
   private CommentService commentService;
    //POST/comments
    //在动态上发表评论
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){
       String movementId = (String) map.get("movementId");
        String comment = (String)map.get("comment");
      commentService.saveComments(movementId,comment);
return ResponseEntity.ok(null);

    }

    //GET/comments
    //查看评论列表
    @GetMapping
    public ResponseEntity findComments(String movementId,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int pageSize){
    PageResult<CommentVo> rp= commentService.findComments(movementId,page,pageSize);
    return ResponseEntity.ok(rp);
    }


}
